package com.udaos.modules.school.services;

import java.util.ArrayList;
import java.util.List;

import org.nutz.aop.interceptor.ioc.TransAop;
import org.nutz.dao.Dao;
import org.nutz.dao.Sqls;
import org.nutz.ioc.aop.Aop;
import org.nutz.ioc.loader.annotation.IocBean;

import com.udaos.common.base.Service;
import com.udaos.common.util.StringUtil;
import com.udaos.models.school.Ud_school_area;
/**
 * 驾校区域范围
 * @author 穆涛涛
 *
 */
@IocBean(args = {"refer:dao"})
public class UdSchoolAreaService extends Service<Ud_school_area>{
	public UdSchoolAreaService(Dao dao) {
		super(dao);
	}

	@Aop(TransAop.READ_COMMITTED)
	public void insertList(List<Ud_school_area> areas) {
		dao().fastInsert(areas);
	}

	@Aop(TransAop.READ_COMMITTED)
	public void updateAreas(String areaid, String id) {
		dao().execute(Sqls.create("delete from ud_school_area where school_id= @id").setParam("id", id));
		
		if(null !=areaid){
        	String []areaids=areaid.split(",");
        	List<Ud_school_area> areas=new ArrayList<Ud_school_area>();
        	for (int i = 0; i < areaids.length; i++) {
        		Ud_school_area area=new Ud_school_area();
        		area.setId(StringUtil.newId32());
        		area.setArea_id(areaids[i]);
        		area.setSchool_id(id);
        		area.setCreateAt((int)(System.currentTimeMillis()/1000));
        		
        		areas.add(area);
			}
        	dao().fastInsert(areas);
        	
        }
		
	}
}
